/**
 * @param {number} dividend
 * @param {number} divisor
 * @return {number}
 */
var divide = function (dividend, divisor) {
  //   let currentDNum = Math.abs(dividend)
  //   const data = Math.abs(divisor)
  //   let index = 0
  //   while (currentDNum >= data) {
  //     currentDNum = currentDNum - data
  //     index++
  //   }
  //   index = [dividend, divisor].filter(item => item < 0).length === 1 ? 0 - index : index
  index = Math.floor(dividend / divisor)
  let finit = Math.pow(2, 31)
  if (index < 0 - finit) {
    index = 0 - finit
  } else if (index >= finit) return finit - 1
  return index
}
console.log(divide(-2147483648, 2))
